home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 374 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  3.8 KB

  1. Path: fido.asd.sgi.com!austern
  2. From: jason@cygnus.com (Jason Merrill)
  3. Newsgroups: comp.std.c++
  4. Subject: Re: Observations on templates
  5. Date: 08 Feb 1996 14:30:35 PST
  6. Organization: Cygnus Support, Mountain View, CA
  7. Approved: austern@isolde.mti.sgi.com
  8. Message-ID: <u9u411zer4.fsf@yorick.cygnus.com>
  9. References: <u9vilu8zvz.fsf@yorick.cygnus.com> <ADqNY6n4sN@qsar.chem.msu.su>
  10. NNTP-Posting-Host: isolde.mti.sgi.com
  11. X-Original-Date: 08 Feb 1996 13:30:55 -0800
  12. In-Reply-To: "Eugene Radchenko"'s message of 8 Feb 1996 17:00:57 GMT
  13. X-Newsreader: Gnus v5.0
  14. X-Auth: PGPMoose V1.1 PGP comp.std.c++
  15.     iQBVAwUBMRp5sky4NqrwXLNJAQEdUwIAvQplNB5+N+FIiihbwHnql1OGLHxKM9hY
  16.     x/rrCqKTKtWFZlQOlyNRk+2Tv3/EEyMttjdE3cHMj21c2mcOePJYrA==
  17.     =clXi
  18. Originator: austern@isolde.mti.sgi.com
  19.  
  20. >>>>> Eugene Radchenko <eugene@qsar.chem.msu.su> writes:
  21.  
  22. > jason@cygnus.com (Jason Merrill) writes
  23. >>>>>>> Eugene Radchenko <eugene@qsar.chem.msu.su> writes:
  24.  
  25. >>> 1) Clause [temp.res] verse 1 requires that all types dependent on the
  26. >>> template parameter must be qualified by 'typename' keyword - supposedly to
  27. >>> allow checking the template syntax. But it does not help anything as _each_
  28. >>> instance will have to be checked anyway:
  29.  
  30. >> Requiring 'typename' allows syntactic analysis and some name binding
  31. >> to be done at the point of definition of the template.  Older
  32. >> implementations do all name binding at the point of instantiation,
  33. >> which was thought to be confusing.
  34.  
  35. >> Each instance will indeed have to be checked, but only for semantic
  36. >> correctness, not syntactic.
  37.  
  38. > And does such a simplification (which does not simplify anything as
  39. > complete recheck is still needed) warrant the introduction of a new
  40. > keyword (why could not at least the 'class' keyword be used like in
  41. > template prefix?).
  42.  
  43. Because 'class' already has semantics in that position, and a new keyword
  44. is really not a significant problem.  If it conflicts with your code, you
  45. can easily work around it with a #define.
  46.  
  47. > Interestingly, WRT member functions (and especially operator->) the
  48. > decision was roughly inverse (i.e. to perform checking only on the
  49. > per-instance basis and only if given instance is required).
  50.  
  51. Nope; function templates, like class templates, are parsed immediately to
  52. do name binding according to the new lookup rules.
  53.  
  54. >>> 2) Clause [temp.dep] verse 5 states that base class scope names hide the
  55. >>> template parameter:
  56.  
  57. >> This is for orthogonality.  Think of the template header as creating a
  58. >> special scope around the class; name lookups in class scope look in the
  59. >> current class, then in base classes, then in the surrounding scope.
  60.  
  61. > That much I do understand. I only think that such an order is
  62. > counter-intuitive.
  63.  
  64. Well, other people don't, apparently.
  65.  
  66. >>> 3) Clause [temp.arg.explicit] verses 2-3 requires that for explicit arg in
  67. >>> member template to be present it must be qualified by 'template' keyword,
  68. >>> e.g.
  69. >>> X *p; p->template alloc<200>();
  70. >>> But to use operator -> we need X class definition anyway - so we know that
  71. >>> alloc() is a template.
  72.  
  73. >> It is needed in some situations where we do not have the X class definition
  74. >> -- in template definitions, like with typename.
  75.  
  76. > And what are we supposed to do with function alloc() if we do not have the
  77. > class definition and hence do not know anything about this function?
  78.  
  79. We only need the 'template' keyword there so we know what '<' means.  If
  80. 'alloc' is a template, it means "begin template arg list".  Otherwise, it
  81. means "less than", and it doesn't matter if 'alloc' is a function or a
  82. field or an enum or whatever; that can wait until semantic analysis at
  83. instantiation time.
  84.  
  85. Jason
  86. ---
  87. [ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  88.   Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy is
  89.   in http://reality.sgi.com/employees/austern_mti/std-c++/policy.html. ]
  90.